﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace lianxi
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.Cookies["Username"]!=null && Request.Cookies["Userpwd"]!=null)
                {
                    TextBox1.Text = Server.UrlDecode(Request.Cookies["Username"].Value);
                    TextBox2.Attributes.Add("value",Request.Cookies["Userpwd"].Value);
                }
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (TextBox1.Text==""||TextBox2.Text=="")
            {
                Response.Write("<script>alert('用户名或密码不能为空')</script>");
            }
            else
            {
                if (TextBox1.Text=="admin")
                {
                    Response.Write("<script>alert('不允许使用管理员账号')</script>");
                }
                else
                {
                    if (cbRem.Checked)
                    {
                        HttpCookie cName = new HttpCookie("Username", Server.UrlEncode(this.TextBox1.Text));
                        HttpCookie cPwd = new HttpCookie("Userpwd", this.TextBox2.Text);
                        //设置保存时间
                        cName.Expires = DateTime.Now.AddDays(1);
                        cPwd.Expires = DateTime.Now.AddDays(1);
                        //加入到cookies集合中
                        Response.Cookies.Add(cName);
                        Response.Cookies.Add(cPwd);
                    }
                    Session["User"] = TextBox1.Text;
                    Response.Redirect("Index.aspx");
                }
            }
            
        }
    }
}